#!/usr/bin/env python

import re

writePos=0
hasEduEmail = 1
firstname=""
lastname=""

readFile = open("slapcat.txt", "r")
writeFile = open("slapcat.txt", "w")
try:
  for line in readFile:	 
    if line.find("dn: ") != -1:  
      #new user       	    
      #check if previous user needed an isu email
      if hasEduEmail == 0:
	#user has not any isu email      
	#return to the last line of the previous user    
	writeFile.seek(writePos)
	#make isu email with 4 letters of the lastname and 4 letters of the firstname
	writeFile.write("mail=newemail@isu.edu")  
      hasEduEmail = 0   
      #save lastname and firstname for next time
      firstname="test"
      lastname="test"
      
    if line.find("mail: ") != -1: 
      #line with email	    
      if line.find("isu.edu") != -1:
	hasEduEmail = 1 
	print line
	
    #save position	
    writePos = readFile.tell() 	    	    
            
   #EOF
  if hasEduEmail == 0:   
    file.write("mail=newemail@isu.edu") 
      
      
   
	      
finally:
  readFile.close()
  writeFile.close()

def makeEmail(firstname, lastname):
  return lastname[0:4] + firstname[0:4] + "@isu.edu"	

if __name__ == "__main__":
  pass